import mixin from "@/mixins/ICPSmixin.js";
import moment from 'moment';
import {
  queryPage,
  query_product_page,
  save_or_update,
  plan_detail,
  getContractVoList,
  operation_detail,
  check_order,
  engineeringManagementQueryListFinish,
  engineeringManagementQueryPage,
  timeget_list,
  stationget_list,
  dataget_list,
  get_assess,
  stationsave_or_update,
  timesave_or_update,
  datasave_or_update,
  init_data,
  plan_table_detail,
  // judgePlanControl,
  updateOrderStatus
} from "@/api/smart/schedul/d.js";
import { planRemark } from "@/api/smart/schedul/c.js";
import { graphic_list } from "@/api/smart/schedul/b.js";
import { getDicType, get_simple_organization, getStationByCompanyId, get_simple_user_listBycompanyId } from "@/api/common.js";
import { getUserInfo } from "@/utils/auth.js";
import { getDisClostDetail } from "@/api/internetSales/projectClarifi.js";
import { cancelPlanByIds } from "@/api/smart/schedul/c.js";
import outsourcing from "./outsourcing"//引入外协拉料
import { getLists } from "@/api/smart/schedul/c.js";
export default {
  components: {//启动组件
    Outsourcing: outsourcing
  },
  mixins: [mixin],
  data() {
    return {
      pickerOptions: {
        disabledDate(orderNo) {
          return orderNo.getTime() < Date.now() - 8.64e7;
        }
      },
      ids: [],
      stationIdlist: [],//当前账号公司得所有站点
      UserInfo: '',
      approvalStatus0: '',
      customerCheckStatus0: '',
      tableParamType: false,
      companylist: [], //公司
      sitelist: [],//站点
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [],
      tableData1: [],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      contractTypelist: [
        {
          value: "订单列表",
          id: 0,
        },
        {
          value: "生产调整",
          id: 1,
        },
        {
          value: "外协拉料",
          id: 2,
        },
      ],
      currenindex: 0,
      tableA: [
        {
          label: "订单编号",
          width: "220",
          prop: "orderNo",
          status: true,
        },
        {
          label: "工程名称",
          width: "160",
          prop: "engineeringName",
          status: true,
        },
        {
          label: "浇筑部位",
          width: "220",
          prop: "structuralParts",
          status: true,
        },
        {
          label: "产品名称",
          prop: "productName",
          width: "140",
          status: true,
        },
        {
          label: "浇筑用量（方）",
          width: "140",
          prop: "pouringNum",
          status: true,
        },
        {
          label: "计划浇筑时间",
          prop: "pouringTime",
          width: "160",
          status: true,
        },
        {
          label: "浇筑方式",
          width: "140",
          prop: "pouringMethod",
          status: true,
        },
        {
          label: "客户名称",
          width: "180",
          prop: "customerName",
          status: true,
        },
        {
          label: "联系人",
          width: "120",
          prop: "person",
          status: true,
        },
        {
          label: "联系电话",
          width: "140",
          prop: "phoneNum",
          status: true,
        },
        {
          label: "订单类型",
          width: "120",
          prop: "orderType",
          status: true,
        },
        {
          label: "下单时间",
          width: "160",
          prop: "createOrderTime",
          status: true,
        },
        {
          label: "审核状态",
          width: "80",
          prop: "",
          status: true,
        },
      ],
      tableB: [
        {
          label: "订单编号",
          width: "220",
          prop: "orderNo",
          status: true,
        },
        {
          label: "工程名称",
          width: "160",
          prop: "engineeringName",
          status: true,
        },
        {
          label: "浇筑部位",
          width: "220",
          prop: "structuralParts",
          status: true,
        },
        {
          label: "产品名称",
          width: "160",
          prop: "productName",
          status: true,
        },
        {
          label: "计划生产量（方）",
          width: "140",
          prop: "pouringNum",
          status: true,
        },
        {
          label: "计划浇筑时间",
          width: "160",
          prop: "pouringTime",
          status: true,
        },
        {
          label: "生产站点",
          width: "120",
          prop: "stationName",
          status: true,
        },
        {
          label: "订单类型",
          width: "120",
          prop: "orderType",
          status: true,
        },
        {
          label: "订单审核人",
          width: "140",
          prop: "submitOrderUserName",
          status: true,
        },
        {
          label: "状态",
          width: "120",
          prop: "",
          status: true,
        },
        {
          label: "操作",
          width: "80",
          prop: "",
          status: true,
        },
      ],
      lookType: false,
      formData: {
        contractId: '',
        engineeringId: "",
        strengthGradeId: "", //强度等级
        performanceGradeId: "", //性能等级
        meterialRequirementsId: "", //材料要求
        specialRequirementsId: "", //特殊要求
        otherRequirementsId: "", //其他要求list
        admixtureRequirements: "", //外加剂要求
        pouringMethod: "", //浇筑方式
        pouringTime: "", //浇筑时间
      },
      lookType2: false,
      /*添加表单数据*/
      rules: {
        structuralParts: [
          {
            required: true,
            message: "请输入浇筑部位",
            trigger: "change",
          },
        ],
        strengthGradeId: [
          {
            required: true,
            message: "请选择强度等级",
            trigger: "change",
          },
        ],
        performanceGradeId: [
          {
            required: true,
            message: "请选择性能等级",
            trigger: "change",
          },
        ],
        meterialRequirementsId: [
          {
            required: true,
            message: "请选择材料要求",
            trigger: "change",
          },
        ],
        specialRequirementsId: [
          {
            required: true,
            message: "请选择特殊要求",
            trigger: "change",
          },
        ],
        otherRequirementsId: [
          {
            required: true,
            message: "请选择其他要求",
            trigger: "change",
          },
        ],
        admixtureRequirements: [
          {
            required: true,
            message: "请选择外加剂要求",
            trigger: "change",
          },
        ],
        pouringMethod: [
          {
            required: true,
            message: "请选择浇筑方式",
            trigger: "change",
          },
        ],
        pouringTime: [
          {
            required: true,
            message: "请选择浇筑时间",
            trigger: "change",
          },
        ],
        pouringNum: [
          {
            required: true,
            message: "请输入浇筑用量",
            trigger: "change",
          },
        ],
        pouringHigh: [
          {
            required: true,
            message: "请输入泵送高度",
            trigger: "change",
          },
        ],
        person: [
          {
            required: true,
            message: "请输入联系人",
            trigger: "change",
          },
        ],
        phoneNum: [
          {
            required: true,
            message: "请输入联系电话",
            trigger: "change",
          },
          { min: 11, max: 11, message: "手机号格式错误", trigger: "change" },
        ],
      },
      rules2: {
        person: [
          {
            required: true,
            message: "请输入联系人",
            trigger: "blur",
          },
        ],
        phoneNum: [
          {
            required: true,
            message: "请输入联系电话",
            trigger: "blur",
          },
        ],
        pouringNum: [
          {
            required: true,
            message: "请输入浇筑用量",
            trigger: "blur",
          },
        ],
        pouringMethod: [
          {
            required: true,
            message: "请输入浇筑方式  ",
            trigger: "change",
          },
        ],
        pouringTime: [
          {
            required: true,
            message: "请选择浇筑时间",
            trigger: "change",
          },
        ],
        pouringHigh: [
          {
            required: true,
            message: "请输入泵送高度",
            trigger: "blur",
          },
        ],
        noteName: [
          {
            required: true,
            message: "请输入票单名称",
            trigger: "blur",
          },
        ],
      },
      rules2_2: {
        pointId: [
          {
            required: true,
            message: "请输入供应站点名称",
            trigger: "change",
          },
        ],
        settleId: [
          {
            required: true,
            message: "请输入结算方式",
            trigger: "change",
          },
        ],
        lossNumId: [
          {
            required: true,
            message: "请输入损耗量",
            trigger: "change",
          },
        ],
        foremanId: [
          {
            required: true,
            message: "请输入前场工长",
            trigger: "change",
          },
        ],
      },
      formData4: {},
      formTable3Total: [], //合计
      formTable3: [], //生产调整组装后的表格数据
      formData3Table: [], //调整里面的表格
      formData3TableCopy: [], //原始表格数据
      formData3TableTimeList: [], //调整里面的表格的时间数据
      formData3TableTimeListCopy: [], //原始时间list
      formData3TableTimeListCopy2: [], //用于调整时间
      formData3TableTable: [], //表格的表头
      formData3TableTableCopy: [], //原始表头list
      toViewList2_1: [], //调整表头生产站点的自主生产list
      toViewList2_2: [], //调整表头生产站点的外协生产list
      addDialog2_1: false,
      addDialog2_2: false,
      engineeringName: "",
      engineeringId: "", //工程id
      planId: "", //计划id
      ToViewType: false,
      toViewList: [],
      tableInfo: {},
      addDialog: false,
      addDialog2: false,
      chooseType: false,
      engineeringManagement: [],
      strengthGradeList: [], //强度list
      performanceGradeList: [], //性能等级list
      meterialRequirementsList: [], //材料要求list
      specialRequirementsList: [], //特殊要求list
      otherRequirementsList: [], //其他要求list
      admixtureRequirementsList: [], //外加剂要求list
      pouringMethodList: [], //浇筑方式list
      structuralPartsList: [], //浇筑部位
      goodPriceList: [],
      formData2: {},
      formData2_2: { remark: '' },
      assess: { isPro: "" }, //是否限制生产 1是 0否
      totalPoureCount: "", //累计浇筑量
      ListArr: [],
      toViewList2: [],
      foremanIdList: [],
      ToViewFun3Name: "",
      radio: {},
      engineeringNameList: [], //工程名称
      orderType: "", //客户还是调整订单
      customerCheckStatus: false, //客户确认状态
      formData5: {},
      multipleSelection: [],
      multipleSelection1: [],
      multipleSelection2: [],
      marginNumberList: [],
      remarkList: [],
      startTimDateEndTimDate: [],
      contractIdList: [],
      addDialogText: '添加订单',
      list: '',
      look0Type: false,
      bussinessVisible: false,
      buspointArr: [],
      servicePoint: '',
      buspointids: [],
    };
  },

  async created() {
    this.UserInfo = await getUserInfo();
    getStationByCompanyId({ id: this.UserInfo.companyId }).then((res) => {
      this.stationIdlist = res.data.map((v) => {
        return {
          id: v.stationId,
          name: v.stationName
        }
      })
    });
    this.tableParam = { ...this.tableParam, startTimDateEndTimDate: [], productName: '', customerName: '', startDate: '', endDate: '', };
    this.init();
    getDicType({
      code: "marginNumber",
    }).then((res) => {
      this.marginNumberList = res.data.items;
    });
    getDicType({
      code: "market",
    }).then((res) => {
      this.buspointArr = res.data.items.map((res) => {
        return { id: res.id, name: res.itemName }
      })
    });
  },
  deactivated() {
    this.addDialog2 = false
  },
  methods: {
    updateOrderStatusFun(row) {
      this.$confirm('此操作将完成订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateOrderStatus({ id: row.planId, customerCheckStatus: 4 }).then((res) => {
          if (res.code == 1001) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.gettableData();
          }
        })
      })
    },
    async modifyFun(row) {
      this.addDialog = true
      this.$data.formData = this.$options.data().formData
      this.$nextTick(() => {
        plan_detail({ id: row.planId }).then(async (res) => {
          this.formData = { ...this.formData, ...res.data }
          await this.contractIdListFun()
          await this.getListsFun()
          this.engineeringManagementQueryListFinishFun()
          if (this.formData.performanceGradeId) {
            this.formData.performanceGradeId = JSON.parse(this.formData.performanceGradeId).map((v) => {
              return v.id
            });
          } else {
            this.formData.performanceGradeId = [];
          }
          if (this.formData.meterialRequirementsId) {
            this.formData.meterialRequirementsId = JSON.parse(this.formData.meterialRequirementsId).map((v) => {
              return v.id
            });
          } else {
            this.formData.meterialRequirementsId = [];
          }
          if (this.formData.specialRequirementsId) {
            this.formData.specialRequirementsId = JSON.parse(this.formData.specialRequirementsId).map((v) => {
              return v.id
            });
          } else {
            this.formData.specialRequirementsId = [];
          }
          if (this.formData.otherRequirementsId) {
            this.formData.otherRequirementsId = JSON.parse(this.formData.otherRequirementsId).map((v) => {
              return v.id
            });
          } else {
            this.formData.otherRequirementsId = [];
          }
          if (this.formData.admixtureRequirements) {
            this.formData.admixtureRequirements = JSON.parse(this.formData.admixtureRequirements).map((v) => {
              return v.id
            });
          } else {
            this.formData.admixtureRequirements = [];
          }
          if (this.formData.pouringMethod) {
            this.formData.pouringMethod = JSON.parse(this.formData.pouringMethod).map((v) => {
              return v.id
            });
          } else {
            this.formData.pouringMethod = [];
          }
          this.$refs.reffromData.clearValidate()
        })
      })
    },
    /**
     * @Description: 获取5大参数、浇筑方式泵机类型
     * @Param: 
     * @Author: wangwangwang
     */
    getListsFun() {
      getLists().then((res) => {
        console.log(res.data);
        res.data.forEach((item) => {
          if (!item) return
          if (item.typeName == "强度等级") {
            this.strengthGradeList = item.list;
          } else if (item.typeName == "规范性能等级") {
            this.performanceGradeList = item.list;
          } else if (item.typeName == "材料要求") {
            this.meterialRequirementsList = item.list;
          } else if (item.typeName == "特殊要求") {
            this.specialRequirementsList = item.list;
          } else if (item.typeName == "外加剂要求") {
            this.admixtureRequirementsList = item.list;
          } else if (item.typeName == "其他要求") {
            this.otherRequirementsList = item.list;
          }
        });
      });
      /**浇筑方式泵机类型 */
      getDicType({
        code: "castingType",
      }).then((res) => {
        res.data.items.map((v1) => v1.type = 1);
        this.pouringMethodList = res.data.items
        getDicType({
          code: "pouringMethod",
        }).then((res) => {
          res.data.items.map((v2) => v2.type = 2)
          this.pouringMethodList = [...this.pouringMethodList, ...res.data.items];
          this.pouringMethodList.forEach((res) => {
            res.name = res.itemName
          })
        });
      });
    },
    /**订单类型查询工程 */
    engineeringManagementQueryListFinishFun(type) {
      if (type) {
        this.formData.engineeringId = ''
      }
      let businessTypeId = '';
      if (this.formData.orderType * 1 == 5) {
        businessTypeId = 2
      } else if (this.formData.orderType * 1 == 4) {
        businessTypeId = 3
      } else if (this.formData.orderType * 1 == 3) {
        businessTypeId = 4
      } else if (this.formData.orderType * 1 == 1) {//市场：交底通过，且在供应中
        businessTypeId =
          engineeringManagementQueryPage({ isAssess: 5, page: 1, pageSize: 9999999 }).then((res) => {
            this.engineeringNameList = res.data.data;
            this.$forceUpdate()
          })
        return
      }
      engineeringManagementQueryListFinish({ businessTypeId }).then((res) => {
        this.engineeringNameList = res.data;
        this.$forceUpdate()
      });
    },
    /**浇筑部位选择后 */
    structuralPartsCheckFun() {
      this.formData.strengthGradeId = ''
      this.formData.performanceGradeId = ''
      this.formData.meterialRequirementsId = ''
      this.formData.specialRequirementsId = ''
      this.formData.otherRequirementsId = ''
      this.formData.admixtureRequirements = ''
      console.log(JSON.parse(JSON.stringify(this.structuralPartsList)))
      let item = this.structuralPartsList.find((v) => v.id == this.formData.structuralParts)
      if (item) {
        this.formData.strengthGradeId = JSON.parse(item.strengthGrade)[0].id
        if (item.performanceGrade) {
          this.formData.performanceGradeId = JSON.parse(item.performanceGrade).map((v) => v.id)
        }
        if (item.meterialRequirements) {
          this.formData.meterialRequirementsId = JSON.parse(item.meterialRequirements).map((v) => v.id)
        }
        if (item.specialRequirements) {
          this.formData.specialRequirementsId = JSON.parse(item.specialRequirements).map((v) => v.id)
        }
        if (item.otherRequirements) {
          this.formData.otherRequirementsId = JSON.parse(item.otherRequirements).map((v) => v.id)
        }
        if (item.admixtureRequirements) {
          this.formData.admixtureRequirements = JSON.parse(item.admixtureRequirements).map((v) => v.id)
        }
      }
    },
    /**工程选择后查询浇筑部位 */
    addDialogFun() {
      console.log(11);
      let day3 = new Date();
      day3.setTime(day3.getTime() + 24 * 60 * 60 * 1000);
      var s3 = day3.getFullYear() + "-" + (day3.getMonth() + 1) + "-" + day3.getDate();
      this.formData.pouringTime = new Date(s3).Format('yyyy-MM-dd') + ' 08:00:00'
      this.formData.engineeringName = this.engineeringName;
      graphic_list({ engineeringId: this.formData.engineeringId }).then((res) => {
        this.structuralPartsList = res.data;
      });
    },
    contractIdFun() {
      let item = this.contractIdList.find((res) => res.contractId == this.formData.contractId)
      this.formData.contractNo = item.contractNumber
    },
    /**协外单位查询 */
    async contractIdListFun(type) {
      if (type) {
        this.formData.contractId = ''
        this.formData.contractNo = ''
      }
      if (!this.formData.stationId) {
        this.$message({
          message: '请先选择站点！',
          type: 'warning'
        });
        this.formData.orderType = ''
        return
      }
      await getContractVoList({
        stationId: this.formData.stationId,
        contractTypeId: 5,
      }).then((res) => {
        this.contractIdList = this.copy(res.data);
      })
    },
    selectableFun(row) {
      if (row.approvalStatus !== 4) {
        return true
      }
    },
    handleSelectionChange(val) {
      this.ids = val
    },
    cancelPlanByIdsFun() {
      if (this.ids.length == 0) {
        this.$message({
          message: '请选择要操作的数据项',
          type: 'warning'
        });
        return;
      }
      this.$confirm('此操作将取消订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let arr = this.ids.map((res) => res.planId)
        cancelPlanByIds(arr).then((res) => {
          if (res.code == 1001) {
            this.ids = []
            this.gettableData();
            this.$message({
              type: 'success',
              message: '订单取消成功!'
            });
          }
        })
      })
    },
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      get_simple_organization({ id: id }).then((res) => {
        this.formData.companyId = res.data.id
        this.formData.company = res.data.name
      });//查询站点所属公司
    },
    /*根据公司获取站点*/
    setstationIdlist(companyId) {
      getStationByCompanyId({ id: companyId }).then((res) => {
        console.log(res.data);
        this.sitelist = res.data;
        this.sitelist.map((v) => {
          v.id = v.stationId
          v.name = v.stationName
        })
      });
    },
    //都是生产调整里面的表格操作-------------------------------------------开始
    addDialog2_2UPFun() {
      //站点保存!!!!!!!!!!!!!!!!!!!!!!!!!
      // console.log(JSON.parse(JSON.stringify(this.multipleSelection1)));
      // console.log(JSON.parse(JSON.stringify(this.multipleSelection2)));
      let arr = [];
      this.multipleSelection1.forEach((v) => {
        //站点的选中项
        let obj = {
          contractId: "", //站点空，如果是主合同单位，则此字段为合同id。
          planId: this.planId,
          foreignId: v.id, //站点id或者主合同单位id。
          foreignName: v.name, //站点名称或者主合同单位名称。
          status: 1, //1正常的，0是需要删除的站点
          foreignType: "type_station", //type_station站点type_unit主合同单位
        };
        arr.push(obj);
      });
      this.multipleSelection2.forEach((v) => {
        //站点的选中项（外协合同）
        let obj = {
          contractId: v.contractId, //站点空，如果是主合同单位，则此字段为合同id。
          planId: this.planId,
          foreignId: v.supplierId, //站点id或者主合同单位id。
          foreignName: v.supplierName, //站点名称或者主合同单位名称。
          status: 1, //1正常的，0是需要删除的站点
          foreignType: "type_unit", //type_station站点type_unit主合同单位
        };
        arr.push(obj);
      });
      let alldata = arr.filter((res) =>
        this.formData3TableTableCopy.some(
          (item) => res.foreignId == item.foreignId
        )
      );
      let deleteData = this.formData3TableTableCopy.filter(
        (res) => !alldata.some((item) => res.foreignId == item.foreignId)
      );
      deleteData.forEach((res) => {
        res.status = 0; //0是删除
      });
      let addData = arr.filter(
        //新增的type默认写死为 1
        (res) => !alldata.some((item) => res.foreignId == item.foreignId)
      );
      let list = [...alldata, ...deleteData, ...addData];
      this.multipleSelection = list;
      if (list.length) {
        let arr1 = list.filter((v) => v.status == 1)
        console.log(arr1);
        if (arr1.length == 0) {
          this.$message({
            message: "生产站至少选择一个！",
            type: "warning",
          });
          return
        }
        console.log(JSON.parse(JSON.stringify(list)), '生产站')
        //调整生产站

        stationsave_or_update(list).then((res) => {
          if (res.code == 1001) {
            this.$refs.toViewList2_1.clearSelection();
            this.$refs.toViewList2_2.clearSelection();
            setTimeout(() => {
              this.addDialog2_2 = false;
              this.getListArr()
            }, 200);
          }
        });
      }
      this.listDataSetFun();
    },
    handleSelectionChange2(val) {
      //站点外协生产选中项
      this.multipleSelection2 = val;
    },
    handleSelectionChange1(val) {
      //站点选中项
      this.multipleSelection1 = val;
    },
    addDialog2_2False() {
      this.$refs.toViewList2_1.clearSelection();
      this.$refs.toViewList2_2.clearSelection();
      setTimeout(() => {
        this.addDialog2_2 = false;
      }, 200);
    },
    addDialog2_2Fun() {
      this.addDialog2_2 = true;
      //站点勾选打开
      this.toViewList2_1 = this.copy(this.sitelist);
      this.multipleSelection1 = [];
      this.multipleSelection1 = this.toViewList2_1.filter((res) =>
        this.formData3TableTable.some(
          (item) =>
            res.id == item.foreignId && item.foreignType == "type_station"
        )
      );
      console.log(JSON.parse(JSON.stringify(this.multipleSelection1)), "看1");
      // this.multipleSelection1 = this.copy(this.multipleSelection1);

      this.$nextTick(() => {
        this.multipleSelection1.forEach((row) => {
          this.$refs.toViewList2_1.toggleRowSelection(row);
        });
      });
      //外协合同显示开始------------------------------
      getContractVoList({
        stationId: this.formData2_2.pointId,
        contractTypeId: 5,
      }).then((res) => {
        this.toViewList2_2 = this.copy(res.data);
        this.multipleSelection2 = [];
        this.multipleSelection2 = this.toViewList2_2.filter((res) =>
          this.formData3TableTable.some(
            (item) => res.supplierId == item.foreignId
          )
        );
        console.log(JSON.parse(JSON.stringify(this.multipleSelection2)), "看2");
        // this.multipleSelection2 = this.copy(this.multipleSelection2);
        this.$nextTick(() => {
          this.multipleSelection2.forEach((row) => {
            this.$refs.toViewList2_2.toggleRowSelection(row);
          });
        });
      });
    },
    formData3TableListCopyAddFun() {
      //日期的添加
      this.formData3TableTimeListCopy2.push({
        planDate: "",
        id: "",
        planId: this.planId,
        status: 1,
      });
    },
    planDateCheck(v, k) {
      for (let index = 0; index < this.formData3TableTimeListCopy2.length; index++) {
        if (k != index && this.formData3TableTimeListCopy2[index].planDate == v.planDate) {
          this.formData3TableTimeListCopy2[index].status = 2
          console.log(this.formData3TableTimeListCopy2);
          this.formData3TableTimeListCopy2.splice(k, 1)
          console.log(this.formData3TableTimeListCopy2);
          return
        }
      }
    },
    formData3TableListCopyDelFun(k) {
      //日期的删除
      if (this.formData3TableTimeListCopy2[k].id == "") {
        this.formData3TableTimeListCopy2.splice(k, 1);
      } else {
        this.formData3TableTimeListCopy2[k].status = 0;
      }
    },
    addDialog2_1UPFun() {
      console.log(9);
      //日期的保存!!!!!!!!!!!!!!!!!!!!!!!!!
      // console.log(this.formData2.pouringTime);
      // console.log(JSON.parse(JSON.stringify(this.formData3TableTimeListCopy2)));
      let type = true;
      this.formData3TableTimeListCopy2.forEach((v) => {
        if (v.planDate == '') {
          type = false;
          this.$message({
            message: "生产调整的时间未选择完整。",
            type: "warning",
          });
        }
      })
      if (type) {
        console.log(JSON.parse(JSON.stringify(this.formData3TableTimeListCopy2)), '时间段')
        //调整时间段
        console.log(11);
        timesave_or_update(this.formData3TableTimeListCopy2).then((res) => {
          if (res.code == 1001) {
            this.addDialog2_1 = false;
            this.getListArr()
          }
        });
      }
    },
    addDialog2_1Fun() {
      //时间勾选打开
      this.addDialog2_1 = true;
      console.log(this.formData3TableTimeList);
      this.formData3TableTimeListCopy2 = this.copy(this.formData3TableTimeList);
      console.log(this.formData3TableTimeListCopy2);
    },
    //都是生产调整里面的表格操作-------------------------------------------结束
    graphic_listFun(d) {
      //根据所选工程查询浇筑部位（图算管理）
      graphic_list({ engineeringId: d }).then((res) => {
        this.structuralPartsList = res.data;
      });
    },
    radioAddFun() {
      //作业安排-泵送，运输，泵管；选择后的显示和赋值
      this.chooseType = false;
      if (this.radio.supplierName) {
        if (this.ToViewFun3Name == "选择泵送队") {
          this.formData2_2.pumpingTeam =
            this.radio.contractNumber + ":" + this.radio.supplierName;
          this.formData2_2.pumpingTeamId = this.radio.contractId;
          this.formData2_2.dataType = this.radio.dataType;
        } else if (this.ToViewFun3Name == "选择罐车合同") {
          this.formData2_2.tankCar =
            this.radio.contractNumber + ":" + this.radio.supplierName;
          this.formData2_2.tankCarId = this.radio.contractId;
        } else if (this.ToViewFun3Name == "选择泵管单位") {
          this.formData2_2.pipeName =
            this.radio.contractNumber + ":" + this.radio.supplierName;
          this.formData2_2.pipeId = this.radio.contractId;
        }
      }
    },
    radioFun(res) {
      //作业安排-泵送，运输，泵管；的单选
      this.radio = res;
    },
    async ToViewFun3(name) {
      if (!this.formData2_2.pointId) {
        this.$message({
          message: '请选择供应站点！',
          type: 'warning'
        });
        return
      }
      //作业安排-泵送，运输，泵管；的弹出列表
      this.chooseType = true;
      this.radio = {};
      let id = "";
      if (name == "泵送") {
        this.ToViewFun3Name = "选择泵送队";
        await getContractVoList({
          stationId: this.formData2_2.pointId,
          contractTypeId: 3,
          facilityType: 1,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.pumpingTeamId;
        });
      } else if (name == "运输") {
        this.ToViewFun3Name = "选择罐车合同";
        await getContractVoList({
          stationId: this.formData2_2.pointId,
          contractTypeId: 2,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.tankCarId;
        });
      } else if (name == "泵管") {
        this.ToViewFun3Name = "选择泵管单位";
        await getContractVoList({
          stationId: this.formData2_2.pointId,
          contractTypeId: 4,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.pipeId;
        });
      }
      this.toViewList2.forEach((v) => {
        if (v.contractId == id) {
          this.radio = v;
        }
      });
    },
    //点击调整
    async ToViewFun2(e, customerCheckStatus, orderType) {
      this.customerCheckStatus = false;
      if (customerCheckStatus == 2 || customerCheckStatus == 3 || customerCheckStatus == 4 || customerCheckStatus == 5 || customerCheckStatus == 6) {
        this.customerCheckStatus = true; //客户确认状态2,4是已确认和已完成，只能查看
      }

      this.orderType = orderType; //客户还是调整订单

      this.addDialog2 = true;
      this.planId = e.planId;
      this.engineeringId = e.engineeringId;
      this.getDisClostDisAddCostFun(e.engineeringId)
      await this.setstationIdlist(e.companyId)
      /**历史备注 */
      planRemark({ planId: this.planId }).then((res) => {
        this.remarkList = res.data
      })
      plan_detail({ id: this.planId }).then((res) => {
        //获取订单信息
        if (res.code == 1001) {
          console.log(res.data);
          this.formData2 = { ...this.formData2, ...res.data };
          console.log(JSON.parse(JSON.stringify(this.formData2)))
          if (this.formData2.noteName == '') {
            this.formData2.noteName = this.formData2.productName
          }
          this.servicePoint = this.formData2.servicePoint ? JSON.parse(this.formData2.servicePoint).map(item => item.name).join(',') : '';
          this.buspointids = this.formData2.servicePoint ? JSON.parse(this.formData2.servicePoint).map(item => item.id) : [];
          this.$forceUpdate()
          operation_detail({
            //获取作业安排信息
            planId: this.planId,
            enginnerId: this.engineeringId,
          }).then((res2) => {
            if (res2.code == 1001) {
              this.formData2_2 = { ...this.formData2_2, ...res2.data }
              this.formData2_2.remark = ''
              if (this.remarkList?.length > 0) {
                this.formData2_2.remark = this.remarkList[0].planRemark
              }
              /**查询前场工长的用户 */
              get_simple_user_listBycompanyId({
                roleId: "e92df33754444146b8e063b9d17ee99b", orgznizationId: this.formData2.companyId
              }).then((res) => {
                this.foremanIdList = res.data;
              });
              get_assess({ engineeringId: this.engineeringId }).then((res3) => {
                if (res3.code == 1001) {
                  if (res3.data) {
                    this.assess.isPro = res3.data.isPro;
                  }
                  //风险管控信息,用于判断是否限制生产！isPro 1是 0否
                  plan_table_detail({ engineeringId: e.engineeringId }).then(
                    (res4) => {
                      if (res4.code == 1001) {
                        if (res4.data) {
                          this.totalPoureCount = res4.data.totalPoureCount;
                        }
                        this.getListArr(); //获取生产调整表格的所有数据
                      }
                    }
                  );
                }
              });
            }
            if (this.formData2.performanceGradeId) {
              this.formData2.performanceGradeId = JSON.parse(this.formData2.performanceGradeId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.performanceGradeId = [];
            }
            if (this.formData2.meterialRequirementsId) {
              this.formData2.meterialRequirementsId = JSON.parse(this.formData2.meterialRequirementsId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.meterialRequirementsId = [];
            }
            if (this.formData2.specialRequirementsId) {
              this.formData2.specialRequirementsId = JSON.parse(this.formData2.specialRequirementsId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.specialRequirementsId = [];
            }
            if (this.formData2.otherRequirementsId) {
              this.formData2.otherRequirementsId = JSON.parse(this.formData2.otherRequirementsId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.otherRequirementsId = [];
            }
            if (this.formData2.admixtureRequirements) {
              this.formData2.admixtureRequirements = JSON.parse(this.formData2.admixtureRequirements).map((v) => {
                return v.id
              });
            } else {
              this.formData2.admixtureRequirements = [];
            }
            if (this.formData2.pouringMethod) {
              this.formData2.pouringMethod = JSON.parse(this.formData2.pouringMethod).map((v) => {
                return v.id
              });
            } else {
              this.formData2.pouringMethod = [];
            }
          });
        }
      });
    },
    /**获取生产调整表格的所有数据*/
    getListArr() {
      stationget_list({ planId: this.planId }).then((res) => {
        //生产站点
        console.log(JSON.parse(JSON.stringify(res.data)), '获取的生产站点')
        if (res.data.length == 0) {
          init_data({ planId: this.planId }).then((res) => {
            if (res.code == 1001) {
              this.getListArr();
            }
          });
        } else {
          this.formData3TableTable = res.data;
          this.formData3TableTableCopy = this.copy(res.data);
          //组装站点list结束
          timeget_list({ planId: this.planId }).then((res) => {
            //时间
            this.formData3TableTimeList = res.data;
            this.formData3TableTimeListCopy = this.copy(res.data);
            dataget_list({ planId: this.planId }).then((res) => {
              //表格数据
              this.formData3Table = res.data;
              this.formData3TableCopy = this.copy(res.data);
              this.arrList(); //筛选返表格值数组中是否有缺少对象，缺少就补一个，表格中才可输入
            });
          });
        }
      });
    },
    listDataSetFunData() {
      //时间删除的
      let delTimeArr = this.formData3TableTimeListCopy2.filter(
        (res) => res.status == 0
      );
      //删除显示的对应数据
      this.formTable3.forEach((res, index) => {
        if (delTimeArr.find((v) => v.id == res.timeId)) {
          this.formTable3.splice(index, 1);
        }
      });
      //站点删除的
      let delSiteArr = this.multipleSelection.filter((res) => res.status == 0);
      let arr = []; //填的数据list
      this.formTable3.forEach((res) => {
        res.dataList.forEach((v) => {
          arr.push(v);
        });
      });
      //删除显示的对应数据
      delSiteArr.forEach((v) => {
        arr.forEach((v2) => {
          console.log(v2.planStationId, v.id);
          if (v2.planStationId == v.id && v2.dataId) {
            v2.status = 0;
          }
        });
      });
      //剩下显示的值只拿填的值
      arr = this.copy(arr.filter((res) => res.status == 0 || res.dataNum != 0));
      let arr2 = []; //原始的数据list
      this.formData3TableCopy.forEach((res) => {
        res.dataList.forEach((v) => {
          arr2.push(v);
        });
      });
      //剩下显示的值只拿填的值，和原始值做对比
      let alldata = arr.filter((res) =>
        arr2.some((item) => res.dataId == item.dataId)
      );
      alldata.forEach((res) => {
        if (res.status != 0) {
          res.status = 1; //1是标准0是删除，这里没有2
        }
      });
      let deleteData = arr2.filter(
        (res) => !alldata.some((item) => res.dataId == item.dataId)
      );
      deleteData.forEach((res) => {
        res.status = 0; //0是删除
      });
      let addData = arr.filter(
        (res) => !alldata.some((item) => res.dataId == item.dataId)
      );
      addData.forEach((res) => {
        res.status = 1; //1是新增
      });
      this.list = [...alldata, ...deleteData, ...addData];
      let type = false
      if (this.assess.isPro == null) {
        let size = 0;
        this.list.forEach((v) => {
          if (v.status != 0) {
            size = Number(size) + Number(v.dataNum);
          }
        });
        console.log(size, this.totalPoureCount, this.formData2.pouringNum);
        if (size + this.totalPoureCount > this.formData2.pouringNum) {
          // this.$message({
          //   message: "生产调整的总量加已浇筑量超过了订单浇筑用量！请更正。",
          //   type: "warning",
          // });
          type = true
        }
      }
      return type
    },
    /**组装修改的表格数据，没有表头和时间*/
    listDataSetFun(type, obj) {
      this.datasave_or_updateFun(type, this.list, obj);
    },
    /**生产调整数据保存，保存后立即组装数据在表格显示 */
    datasave_or_updateFun(type, list, obj) {
      console.log(list);
      console.log(obj);
      // console.log(JSON.parse(JSON.stringify(list)), '表格')
      //obj是表单的基础数据，list是表格数据
      if (obj) {
        console.log('保存obj');
        let type1 = false//type1=true表示走签核
        // console.log(this.formData3TableTable)
        this.formData3TableTable.forEach((v) => {
          console.log(v.contractId);
          if (v.contractId) {
            type1 = true
          }
        })
        //计划审核，同时支持修改订单信息和作业安排,同时修改审核状态
        check_order(obj).then(() => {
        });
        if (type1) {
          this.$router.push({ name: "sign_smartscheduld", query: { obj: JSON.stringify(obj), list: JSON.stringify(list), formTable3: JSON.stringify(this.formTable3), formData3TableTable: JSON.stringify(this.formData3TableTable), formData3TableTimeList: JSON.stringify(this.formData3TableTimeList), formTable3Total: JSON.stringify(this.formTable3Total), type: 1 } })
          return
        }
      }
      // console.log(JSON.parse(JSON.stringify(list)), '表格')
      //保存生产调整表格的信息，没有时间生产站！！！！！！！！！！！！！！！！！！！！！！
      //生产调整数据
      if (list.length) {
        console.log('保存list');
        datasave_or_update(list).then((res2) => {
          if (res2.code == 1001) {
            if (type) {
              this.addDialog2 = false;
              this.$message({
                message: "操作成功",
                type: "success",
              });
              this.query_product_pageFun();
            } else {
              this.getListArr(); //重新装数据
            }
          }
        });
      }
    },
    //组合表格数据
    arrList() {
      // //数据就等于时间list，给list增加一个下级list空数组装个站点的量
      // console.log(
      //   JSON.parse(JSON.stringify(this.formData3TableTimeList)),
      //   "时间"
      // );
      this.formTable3 = this.copy(this.formData3Table);
      //某个日期里面完全没有参数，就要创建对象
      this.formData3TableTimeList.forEach((res) => {
        let type = this.formTable3.some((item) => {
          if (res.id == item.timeId) {
            return true;
          }
        });
        if (!type) {
          this.formTable3.push({
            planDate: res.planDate,
            planId: res.planId,
            timeId: res.id,
            dataList: [],
          });
        }
      });
      console.log(
        JSON.parse(JSON.stringify(this.formTable3)),
        "表格数据-第一层完整了"
      );
      console.log(JSON.parse(JSON.stringify(this.formData3TableTable)), "站点");
      this.formData3Table.forEach((v) => {
        let arr = [];
        v.dataList.forEach((v2) => {
          let k2 = false;
          //循环表头站点，找到当前数据是第几个表头站点list中的
          k2 = this.forTableSize(v2.planStationId);
          //表格数据下标的对应的list下标中
          if (k2 !== false) {
            arr[k2] = v2;
            v.dataList = this.copy(arr);
          }
        });
        //循环时间，找到当前数据是第几个时间list中的
      });
      console.log(JSON.parse(JSON.stringify(this.formData3Table)), "数据");
      // //循环数据，把不存在的下标数据都设置0，占位，
      let length = this.formData3TableTable.length;
      this.formData3Table.forEach((v, k) => {
        for (let i = 0; i < length; i++) {
          if (v.dataList[i] == undefined) {
            const obj = {
              dataNum: 0,
              planId: this.planId, //计划id
              planStationId: this.formData3TableTable[i].id, //站点id
              planTimeId: this.formData3Table[k].timeId, //时间id
            };
            v.dataList.splice(i, 1, obj);
          }
        }
      });
      this.formTable3 = this.copy(this.formData3Table);
      console.log(JSON.parse(JSON.stringify(this.formTable3)), "表格数据-第二层完整了");
      console.log(JSON.parse(JSON.stringify(this.formData3TableTimeList)), "表格时间");
      console.log(JSON.parse(JSON.stringify(this.formData3TableTable)), "表格头部");
      this.numberTotalFun();
    },
    //计算合计
    numberTotalFun() {
      setTimeout(() => {
        this.formTable3Total = [];
        // console.log(JSON.parse(JSON.stringify(this.formData3TableTimeList)));
        this.formData3TableTimeList.forEach((res) => {
          let size = 0;
          this.formTable3.find((v) => v.timeId == res.id)
            .dataList.forEach((res2) => {
              size = Number(size) + Number(res2.dataNum);
            });
          this.formTable3Total.push(size);
        });
        // console.log(JSON.parse(JSON.stringify(this.formTable3Total)), "合计");
      }, 50)
    },
    //循环表头站点，找到当前数据是第几个表头站点list中的
    forTableSize(id) {
      let size = false;
      this.formData3TableTable.forEach((v, k) => {
        if (v.id == id) {
          size = k;
        }
      });
      if (size !== false) {
        return size;
      } else {
        return false;
      }
    },
    //保存并通知客户
    submit2(approvalStatus) {
      this.$refs.reffromData2.validate((valid) => {
        if (valid) {
          this.$refs.reffromData2_2.validate((valid) => {
            if (valid) {
              this.listDataSetFunData()
              // if (this.listDataSetFunData()) {
              //   return
              // }
              //通过和未通过
              this.formData2.approvalStatus = approvalStatus;
              //性能等级-开始数据重装
              if (this.formData2.performanceGradeId.length > 0) {
                let arr = [];
                this.formData2.performanceGradeId.forEach((v) => {
                  this.performanceGradeList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.performanceGradeId = arr;
              }
              this.formData2.performanceGradeId = JSON.stringify(this.formData2.performanceGradeId);
              this.formData2.performanceGrade = this.formData2.performanceGradeId;
              //材料要求-开始数据重装
              if (this.formData2.meterialRequirementsId.length > 0) {
                let arr = [];
                this.formData2.meterialRequirementsId.forEach((v) => {
                  this.meterialRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.meterialRequirementsId = arr;
              }
              this.formData2.meterialRequirementsId = JSON.stringify(this.formData2.meterialRequirementsId);
              this.formData2.meterialRequirements = this.formData2.meterialRequirementsId;
              //特殊要求-开始数据重装
              if (this.formData2.specialRequirementsId.length > 0) {
                let arr = [];
                this.formData2.specialRequirementsId.forEach((v) => {
                  this.specialRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.specialRequirementsId = arr;
              }
              this.formData2.specialRequirementsId = JSON.stringify(this.formData2.specialRequirementsId);
              this.formData2.specialRequirements = this.formData2.specialRequirementsId;
              //其他要求-开始数据重装
              if (this.formData2.otherRequirementsId.length > 0) {
                let arr = [];
                this.formData2.otherRequirementsId.forEach((v) => {
                  this.otherRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.otherRequirementsId = arr;
              }
              this.formData2.otherRequirementsId = JSON.stringify(this.formData2.otherRequirementsId);
              this.formData2.otherRequirements = this.formData2.otherRequirementsId;
              //外加剂要求-开始数据重装
              if (this.formData2.admixtureRequirements.length > 0) {
                let arr = [];
                this.formData2.admixtureRequirements.forEach((v) => {
                  this.admixtureRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.admixtureRequirements = arr;
              }
              this.formData2.admixtureRequirements = JSON.stringify(this.formData2.admixtureRequirements);
              //浇筑方式-开始数据重装
              if (this.formData2.pouringMethod.length > 0) {
                let arr = [];
                this.formData2.pouringMethod.forEach((v) => {
                  this.pouringMethodList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                        type: v2.type,
                      });
                    }
                  });
                });
                this.formData2.pouringMethod = arr;
              }
              this.formData2.pouringMethod = JSON.stringify(this.formData2.pouringMethod);
              console.log(JSON.parse(JSON.stringify(this.formData2.pouringMethod)))

              this.formData2_2.organizationId = this.formData2_2.pointId
              this.formData2.customerCheckStatus = 1
              let remark = ''
              if (this.remarkList.length == 0 && this.formData2_2.remark != '') {
                remark = this.formData2_2.remark
              } else if (this.remarkList.length > 0) {
                if (this.formData2_2.remark != this.remarkList[0].planRemark) {
                  remark = this.formData2_2.remark
                }
              }
              let obj = {
                arrangement: this.formData2_2,
                engineeringPlan: this.formData2,
                remark: remark,//客户订单备注修改
              };
              /**
               * @Description: 判断流程是否被管控
               * @Param: 
               * @Author: wangwangwang
               */
              if (this.servicePoint.length == 0 || (this.servicePoint.length > 0 && this.servicePoint.split(',').findIndex((res) => res == '客户计划确认') == -1)) {
                obj.engineeringPlan.customerCheckStatus = 2;
                obj.engineeringPlan.erpStatus = 1;
                obj.engineeringPlan.customerCheckTime = moment().format('YYYY-MM-DD HH:mm:ss');
              }
              this.datasave_or_updateFun(true, this.list, obj);
            } else {
              return false;
            }
          });
        } else {
          return false;
        }
      });
    },
    //添加计划
    submit() {
      this.$refs.reffromData.validate((valid) => {
        if (valid) {
          //性能等级-开始数据重装
          if (this.formData.performanceGradeId.length > 0) {
            let arr = [];
            this.formData.performanceGradeId.forEach((v) => {
              this.performanceGradeList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.performanceGradeId = arr;
            this.formData.performanceGradeId = JSON.stringify(this.formData.performanceGradeId);
            this.formData.performanceGrade = this.formData.performanceGradeId;
          } else {
            this.formData.performanceGradeId = ''
          }
          //材料要求-开始数据重装
          if (this.formData.meterialRequirementsId.length > 0) {
            let arr = [];
            this.formData.meterialRequirementsId.forEach((v) => {
              this.meterialRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.meterialRequirementsId = arr;
            this.formData.meterialRequirementsId = JSON.stringify(this.formData.meterialRequirementsId);
            this.formData.meterialRequirements = this.formData.meterialRequirementsId;
          } else {
            this.formData.meterialRequirementsId = ''
          }
          //特殊要求-开始数据重装
          if (this.formData.specialRequirementsId.length > 0) {
            let arr = [];
            this.formData.specialRequirementsId.forEach((v) => {
              this.specialRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.specialRequirementsId = JSON.stringify(arr);
            this.formData.specialRequirements = this.formData.specialRequirementsId;
          } else {
            this.formData.specialRequirementsId = ''
          }
          //其他要求-开始数据重装
          if (this.formData.otherRequirementsId.length > 0) {
            let arr = [];
            this.formData.otherRequirementsId.forEach((v) => {
              this.otherRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.otherRequirementsId = JSON.stringify(arr);
            this.formData.otherRequirements = this.formData.otherRequirementsId;
          } else {
            this.formData.otherRequirementsId = ''
          }
          //外加剂要求-开始数据重装
          if (this.formData.admixtureRequirements.length > 0) {
            let arr = [];
            this.formData.admixtureRequirements.forEach((v) => {
              this.admixtureRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.admixtureRequirements = JSON.stringify(arr);
          } else {
            this.formData.admixtureRequirements = ''
          }
          //浇筑方式-开始数据重装
          if (this.formData.pouringMethod.length > 0) {
            let arr = [];
            this.formData.pouringMethod.forEach((v) => {
              this.pouringMethodList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                    type: v2.type,
                  });
                }
              });
            });
            this.formData.pouringMethod = JSON.stringify(arr);
          } else {
            this.formData.pouringMethod = ''
          }
          this.formData.approvalStatus = 2;
          this.formData.customerCheckStatus = 0;
          this.structuralPartsFun()
          save_or_update(this.formData).then((res) => {
            if (res.code == 1001) {
              this.addDialog = false;
              if (this.addDialogText == '添加订单') {
                this.$message({
                  message: "添加成功",
                  type: "success",
                });
              } else {
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              }
              this.gettableData();
            }
          });
        } else {
          return false;
        }
      });
    },
    lookFun(e) {
      this.lookType = true;
      /**历史备注 */
      planRemark({ planId: e.planId }).then((res) => {
        this.remarkList = res.data
      })
      plan_detail({ id: e.planId }).then((res) => {
        //获取订单信息
        this.formData4 = res.data;
        if (this.formData4.performanceGrade) {
          this.formData4.performanceGrade = JSON.parse(this.formData4.performanceGrade).map((v) => {
            return v.name
          });
          this.formData4.performanceGrade = this.formData4.performanceGrade.join(',')
        } else {
          this.formData4.performanceGrade = '';
        }
        if (this.formData4.meterialRequirements) {
          this.formData4.meterialRequirements = JSON.parse(this.formData4.meterialRequirements).map((v) => {
            return v.name
          });
          this.formData4.meterialRequirements = this.formData4.meterialRequirements.join(',')
        } else {
          this.formData4.meterialRequirements = '';
        }
        if (this.formData4.specialRequirements) {
          this.formData4.specialRequirements = JSON.parse(this.formData4.specialRequirements).map((v) => {
            return v.name
          });
          this.formData4.specialRequirements = this.formData4.specialRequirements.join(',')
        } else {
          this.formData4.specialRequirements = '';
        }
        if (this.formData4.otherRequirements) {
          this.formData4.otherRequirements = JSON.parse(this.formData4.otherRequirements).map((v) => {
            return v.name
          });
          this.formData4.otherRequirements = this.formData4.otherRequirements.join(',')
        } else {
          this.formData4.otherRequirements = '';
        }
        operation_detail({
          //获取作业安排信息
          planId: e.planId,
          enginnerId: e.engineeringId,
        }).then((res2) => {
          let obj = {
            point: res2.data.pointName,
            settle: "",
            lossNumId: res2.data.lossNumId,
            remark2: res2.data.remark,
            settleName: res2.data.settleName,
            settleId: res2.data.settleId,
            lossNum: res2.data.lossNum,
            foreman: res2.data.foreman,
          };
          this.formData4 = { ...this.formData4, ...obj };
        });
      });
    },
    init() {
      /*重置数据*/
      this.$data.tableParam = this.$options.data().tableParam;
      this.approvalStatus0 = ''
      this.tableParam.approvalStatus = ''
      if (this.currenindex == 1) {
        this.tableParam.approvalStatus = 2;
        this.customerCheckStatus0 = '';
        this.tableParam.customerCheckStatus = '';
        this.query_product_pageFun()
        return
      }
      this.gettableData();
    },
    choose(num) {
      this.$data.tableParam = this.$options.data().tableParam;
      this.currenindex = num;
      if (this.currenindex == 0) {
        this.approvalStatus0 = ''
        this.tableParam.approvalStatus = "";
        this.gettableData();
      } if (this.currenindex == 1) {
        this.tableParam.approvalStatus = 2;
        this.query_product_pageFun()
      } else {
        this.tableParam.approvalStatus = 2;
        this.gettableData();
      }
    },
    chongZhi() {
      this.engineeringNameList = []
      this.$data.formData = this.$options.data().formData
      this.$nextTick(() => {
        this.$refs.reffromData.clearValidate()
        this.$data.formData.approvalStatus = 2
        this.$data.formData.customerCheckStatus = 2
      })
    },
    chongZhi2() {
      this.formTable3 = []
      this.$data.formData2 = this.$options.data().formData2
      setTimeout(() => {
        this.$refs.reffromData2.clearValidate()
      }, 100)
    },
    /**浇筑部位校验是输入还是选择 */
    structuralPartsFun() {
      let item = this.structuralPartsList.find((v) => v.id == this.formData.structuralParts)
      if (item) {
        this.formData.structuralPartsId = this.formData.structuralParts
        this.formData.structuralParts = item.structuralParts
      } else {
        this.formData.structuralPartsId = ''
      }
    },
    /**查询该工程的强度等级+各项要求+浇筑部位 */
    getDisClostDisAddCostFun(id) {
      getDisClostDetail({ id }).then(res => {
        if (res.code === 1001 && res.data) {
          this.strengthGradeList = JSON.parse(res.data.strengthGrade);
          this.performanceGradeList = JSON.parse(res.data.performanceRate);
          //材料要求pouringMethodList
          this.meterialRequirementsList = JSON.parse(res.data.materialRequirements);
          //特殊要求
          this.specialRequirementsList = JSON.parse(res.data.specialRequirements);
          //外加剂要求
          this.admixtureRequirementsList = JSON.parse(res.data.admixtureRequirements);
          //其他要求
          this.otherRequirementsList = JSON.parse(res.data.otherRequirements);
          //浇筑方式
          this.pouringMethodList = JSON.parse(res.data.pumpType);
        }
      })
    },
    look0Fun(low) {
      this.$data.formData = this.$options.data().formData
      this.look0Type = true
      this.addDialogText = '订单详情'
      plan_detail({ id: low.planId }).then((res) => {
        //获取订单信息
        this.formData = res.data;
        this.engineeringManagementQueryListFinishFun()
        if (this.formData.performanceGrade) {
          this.formData.performanceGrade = JSON.parse(this.formData.performanceGrade).map((v) => {
            return v.name
          });
          this.formData.performanceGrade = this.formData.performanceGrade.join(',')
        } else {
          this.formData.performanceGrade = '';
        }
        if (this.formData.meterialRequirements) {
          this.formData.meterialRequirements = JSON.parse(this.formData.meterialRequirements).map((v) => {
            return v.name
          });
          this.formData.meterialRequirements = this.formData.meterialRequirements.join(',')
        } else {
          this.formData.meterialRequirements = '';
        }
        if (this.formData.specialRequirements) {
          this.formData.specialRequirements = JSON.parse(this.formData.specialRequirements).map((v) => {
            return v.name
          });
          this.formData.specialRequirements = this.formData.specialRequirements.join(',')
        } else {
          this.formData.specialRequirements = '';
        }
        if (this.formData.otherRequirements) {
          this.formData.otherRequirements = JSON.parse(this.formData.otherRequirements).map((v) => {
            return v.name
          });
          this.formData.otherRequirements = this.formData.otherRequirements.join(',')
        } else {
          this.formData.otherRequirements = '';
        }
      })
    },
    query_product_pageFun() {//生产调整
      console.log(11);
      query_product_page(this.tableParam).then((res) => {
        // this.tableData1 = res.data.data
        this.total = res.data.totalRows
        if (res.data.data.length > 0) {
          let d = res.data.data;
          let orderNo = "",
            customerCheckStatus = "",
            sizeY = "";
          let arr = [];
          d.forEach((v) => {
            if (v.list.length > 0) {
              sizeY = v.list.length;
              orderNo = v.orderNo
              customerCheckStatus = v.customerCheckStatus
              let obj = {
                sizeY: sizeY,
                type: false,
              };
              v.list.forEach((v2, k2) => {
                let obj2 = {
                  ...v,
                  ...v2,
                  orderNo: orderNo,
                  customerCheckStatus: customerCheckStatus,
                }
                if (k2 != 0) {
                  obj.sizeY = 0
                }
                arr.push({ ...obj, ...obj2 });
              });
              //orderNo这里其实是计算的合计
            } else {
              v.sizeY = 1
              arr.push(v);
            }
          });
          this.tableData1 = arr;
          console.log(JSON.parse(JSON.stringify(this.tableData1)))
          this.$nextTick(() => {
            this.$refs.table1.doLayout()
          })
        }
      })
    },
    //合并行列
    objectSpanMethod({ row, columnIndex }) {
      //第一列合并列数，被合并的要返回[0,0]
      if (columnIndex == 0) {
        return [row.sizeY, 1]
      } else if (columnIndex == 0) {
        return [0, 0]
      }
      if (columnIndex == 9) {
        return [row.sizeY, 1]
      } else if (columnIndex == 9) {
        return [0, 0]
      }
      if (columnIndex == 10) {
        return [row.sizeY, 1]
      } else if (columnIndex == 10) {
        return [0, 0]
      }
      //第二列合并行数，被合并的要返回[0,0]
      // if (row.type && columnIndex == 1) {
      //   return [1, 5]
      // } else if (row.type && columnIndex > 1) {
      //   return [0, 0]
      // }
    },
    choiseBussinessPoint() {
      this.bussinessVisible = true;
    },
    handlePoint() {
      const newData = this.buspointArr.filter(item => this.buspointids.some(items => item.id === items));
      console.log(newData)
      this.servicePoint = newData.map(item => item.name).join(',');
      this.formData2.servicePoint = JSON.stringify(newData.map(item => ({ id: item.id, name: item.name, type: 1 })));
      this.bussinessVisible = false;
    },
  },
  filters: {
    pouringMethodFilter(e) {
      if (e) {
        e = JSON.parse(e)
        let table = e.map((res) => res.name)
        let text = table.join('、')
        return text
      }
    },
  }
};
